#define _CRT_SECURE_NO_WARNINGS


lass Gift{
public:
    int getValue(vector<int> gifts, int n) {
        // write code here
        int min = gifts[0];
        int max = gifts[0];
        for (int i = 0; i < n; i++)
        {
            if (gifts[i] > max)
                max = gifts[i];
            if (gifts[i] < min)
                min = gifts[i];
        }
        vector<int> num(max - min + 1,0);
        for (int i = 0; i < n; i++)
        {
            num[gifts[i] - min]++;
        }
        int j = 0;
        int flag = 0;
        for (j = 0; j < max - min + 1; j++)
        {
            int ret = num[j] * 2;
            if (ret >= n)
            {
                flag = 1;
                break;
            }
        }
        if (flag)
        {
            return j + min;
        }
        return 0;

    }
};